package com.guomao.methodrefer;

public class ReferDemo1 {

    public static void main(String[] args) {
//        refer1();
//        refer2();

//        refer3();

        refer4();


    }

    private static void refer4() {
    /*PersonCreator pc = new PersonCreator() {
        @Override
        public Person create(String name, int age) {
            return new Person(name, age);
        }
    };*/

      /*  PersonCreator pc = (name, age) -> {
            return new Person(name, age);
        };*/

//        PersonCreator pc = (name, age) -> new Person(name, age);
        PersonCreator pc = Person::new;
    }

    private static void refer3() {
    /*new LengthChecker() {
        @Override
        public int checkLength(String s) {
            return s.length();
        }
    };*/

//        LengthChecker c = (s)->{return s.length();};
//        LengthChecker c = (s)-> s.length();
        //length是定义在String 类中的
        LengthChecker c = String::length;
    }

    private static void refer2() {
        StringBuilder sb = new StringBuilder();

       /* new StringTransformer() {
            @Override
            public String transform(String s) {
                return sb.append("helloworld").toString();
            }
        };*/

      /*  StringTransformer st = (s) -> {
            return sb.append("helloworld").toString();
        };*/

//        StringTransformer st = (s) -> sb.append("helloworld").toString();
//        StringTransformer st = sb::append;
    }

    private static void refer1() {
        StringTransformer st1 = new StringTransformer() {
            @Override
            public StringBuilder transform(String s) {
                return StringUtils.reverse(s);
            }
        };
//        StringTransformer st2 = (str) -> {return StringUtils.reverse(str);};
//        StringTransformer st2 = (str) ->  StringUtils.reverse(str);
//        StringTransformer st2 = StringUtils::reverse;
    }

}
